import Vue from "vue"
import VueRouter from "vue-router"

const originalPush = VueRouter.prototype.push;

VueRouter.prototype.push = function push(location) {

  return originalPush.call(this, location).catch((err) => err);

};


Vue.use(VueRouter)


const router=new VueRouter({
	mode:'history',
	routes:[
		{
			name:'login',
			path:'/login',
			component:()=> import('@/page/login.vue')
		},{
			path:'/',
			component:()=> import('@/page/home.vue'),
			redirect:'/index',
			children:[
				{
					name:'',
					path:'/index',
					component:()=> import('@/components/shenqingren.vue')
				},{
					name:'',
					path:'/jilu',
					component:()=> import('@/components/shenbaojilu.vue')
				},{
					path:'/download',
					component:()=> import('@/components/DownloadCenter.vue')
				},{
					path:'/notice',
					component:()=> import('@/components/Notice.vue')
				},{
					path:'/inquiry',
					component:()=> import('@/components/Inquiry.vue')
				},{
					path:'/technicalsupport',
					component:()=> import('@/components/TechnicalSupport.vue')
				},{
					path:'/notice/details',
					component:()=> import('@/components/Details.vue')
				},{
					path: '/study',
					component:()=>import('@/components/StudyExperience.vue')
				},{
					path: '/work',
					component:()=>import('@/components/WorkExperience.vue')
				},{
					path: '/officebefore',
					component:()=>import('@/components/OfficeBefore.vue')
				},{
					path: '/officelater',
					component:()=>import('@/components/OfficeAfter.vue')
				},{
					path: '/literature',
					component:()=>import('@/components/LiteratureRecord.vue')
				},{
					path: '/reply',
					component:()=>import('@/components/Reply.vue')
				},{
					path: '/yearaudit',
					component:()=>import('@/components/YearAudit.vue')
				},{
					path: '/recommend',
					component:()=>import('@/components/Recommendation.vue')
				},{
					path: '/reviewopinion',
					component:()=>import('@/components/ReviewOpinion.vue')
				},{
					path: '/evaluation',
					component:()=>import('@/components/Evaluationtable.vue')
				},{
					path: '/uploadfile',
					component:()=>import('@/components/UploadFile.vue')
				},{
					path: '/evaluation',
					component:()=>import('@/components/Evaluationtable.vue')
				},{
                    path:"/activity/more",
                    component:()=> import('@/components/ActivityList.vue'),

				},{
					path:"/activity/details",
					component:()=> import('@/components/ActivityDetail.vue'),
				}
			]
		},{
			name:'passwordRetrieval',
			path:'/pwdRetr',
			component:()=> import('@/page/passwordRetrieval.vue'),

		},{
			name:'register',
			path:'/register',
			component:()=> import('@/page/register.vue'),

		},{
			path:'/view',
			component:()=> import('@/components/fileView.vue'),
		},
		{
			path:"*",
			component:()=> import('@/components/Error404.vue'),
		}
	]

});





router.beforeEach((to, from, next) => {
    //获取用户令牌
	let token= localStorage.getItem("token")
	//不需要认证的路由
	let noAuthRouter=["/login","/register","/pwdRetr"]
	if(noAuthRouter.indexOf(to.path)<0 &&!token){
		next("/login")
	}


	next();

})

export default router;
